﻿using AviewLightSource;
using AviewLightSource.Views;
using AviewMotionUI.MachineLife;
using FinalTestMachine.Motion;
using FinalTestMachine.Motion.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Wpf_LoginWnd;
using WpfZMotion_AAControl.Core.Tools;

namespace FinalTestMachine.View.MainUnits
{
    /// <summary>
    /// Unit_MainTopMenu.xaml 的交互逻辑
    /// </summary>
    public partial class Unit_MainTopMenu : UserControl
    {
        public Unit_MainTopMenu()
        {
            InitializeComponent();

            IUserLimitdll.PreControlBindingHelper.SetLitmitBinding(menu_Motion, IUserLimitdll.UserLevelModes.ModifyAndOperation);
            IUserLimitdll.PreControlBindingHelper.SetLitmitBinding(menu_Test, IUserLimitdll.UserLevelModes.ModifyAndOperation);
            IUserLimitdll.PreControlBindingHelper.SetLitmitBinding(menu_Settings, IUserLimitdll.UserLevelModes.ModifyAndOperation);
            IUserLimitdll.PreControlBindingHelper.SetLitmitBinding(menu_SettingFunc, IUserLimitdll.UserLevelModes.Top);
        }

        private void menu_Motion_Click(object sender, RoutedEventArgs e)
        {
            Wnd_Motion.SingleShow();
        }

        private void menu_WorkItemManager_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (Motion.Process.Process_AutoRun.Cur.IsRunning)
                {
                    MessageBox.Show("当前正在自动运行模式，无法进入设置界面进行参数更改，请先停止设备自动运行状态");
                    return;
                }
                WorkItemHelper2.MainWindow window = new WorkItemHelper2.MainWindow(WorkItemManagerHelper.workIterm);
                window.Owner = Window.GetWindow(this);
                window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                window.ShowDialog();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void menuLogin_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Wpf_LoginWnd.LoginMainWnd wnd = new Wpf_LoginWnd.LoginMainWnd();
                wnd.Owner = Window.GetWindow(this);
                wnd.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                wnd.ShowDialog();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void menu_BaseFunsSetting_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (Motion.Process.Process_AutoRun.Cur.IsRunning)
                {
                    MessageBox.Show("当前正在自动运行模式，无法进入设置界面进行参数更改，请先停止设备自动运行状态");
                    return;
                }
                Window wnd = new Wnd_FunsSetting();
                wnd.Owner = Window.GetWindow(this);
                wnd.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                IUserLimitdll.PreControlBindingHelper.SetLitmitBinding(wnd, IUserLimitdll.UserLevelModes.ModifyAndOperation);
                wnd.ShowDialog();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }
        private void Menu_SettingFunc_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Wpf_LoginWnd.Wnd_LoginFunc wnd = new Wpf_LoginWnd.Wnd_LoginFunc();
                wnd.Owner = Window.GetWindow(this);
                wnd.WindowStartupLocation = WindowStartupLocation.CenterOwner;

                wnd.ShowDialog();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        //private void menu_Site2_Click(object sender, RoutedEventArgs e)
        //{
        //    try
        //    {
        //        TCPHelper3.ServerWindow window = new TCPHelper3.ServerWindow(Connect.ConnectFactory.connectSite2 as TCPHelper3.ConnectServerHelper);
        //        window.Loaded += delegate { Connect.ConnectFactory.IsSetting = true; };
        //        window.Closed += delegate { Connect.ConnectFactory.IsSetting = false; };
        //        window.ShowDialog();
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //    }
        //}

        //private void menu_Site3_Click(object sender, RoutedEventArgs e)
        //{
        //    try
        //    {
        //        TCPHelper3.ServerWindow window = new TCPHelper3.ServerWindow(Connect.ConnectFactory.connectSite3 as TCPHelper3.ConnectServerHelper);
        //        window.Loaded += delegate { Connect.ConnectFactory.IsSetting = true; };
        //        window.Closed += delegate { Connect.ConnectFactory.IsSetting = false; };
        //        window.ShowDialog();
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //    }
        //}

        //private void menu_Site4_Click(object sender, RoutedEventArgs e)
        //{
        //    try
        //    {
        //        TCPHelper3.ServerWindow window = new TCPHelper3.ServerWindow(Connect.ConnectFactory.connectSite4 as TCPHelper3.ConnectServerHelper);
        //        window.Loaded += delegate { Connect.ConnectFactory.IsSetting = true; };
        //        window.Closed += delegate { Connect.ConnectFactory.IsSetting = false; };
        //        window.ShowDialog();
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //    }
        //}

        //private void menu_ScanCode_Click(object sender, RoutedEventArgs e)
        //{
        //    try
        //    {
        //        SerialPortDemo3.MainWindow mainWindow = new SerialPortDemo3.MainWindow(Connect.ConnectFactory.SerialPort_ScanCode as SerialPortDemo3.ConnectSerialPortHelper);
        //        mainWindow.Height = 600;
        //        mainWindow.Loaded += delegate {
        //            Connect.ConnectFactory.IsSetting = true;
        //        };
        //        mainWindow.Closed += delegate 
        //        {
        //            Connect.ConnectFactory.IsSetting = false;
        //        };
        //        mainWindow.Title = "上料扫码";
        //        IUserLimitdll.PreControlBindingHelper.SetLitmitBinding(mainWindow, IUserLimitdll.UserLevelModes.ModifyAndOperation);
        //        mainWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
        //        mainWindow.ShowDialog();


        //    }
        //    catch (Exception ex)
        //    {

        //        MessageBox.Show(ex.Message);
        //    }
        //}

        //private void menu_ScanSocket_Click(object sender, RoutedEventArgs e)
        //{
        //    try
        //    {
        //        SerialPortDemo3.MainWindow mainWindow = new SerialPortDemo3.MainWindow(Connect.ConnectFactory.SerialPort_ScanSocket as SerialPortDemo3.ConnectSerialPortHelper);
        //        mainWindow.Height = 600;

        //        mainWindow.Loaded += delegate {
        //            Connect.ConnectFactory.IsSetting = true;
        //        };

        //        mainWindow.Closed += delegate
        //        {
        //            Connect.ConnectFactory.IsSetting = false;
        //        };
        //        mainWindow.Title = "治具扫码";
        //        IUserLimitdll.PreControlBindingHelper.SetLitmitBinding(mainWindow, IUserLimitdll.UserLevelModes.ModifyAndOperation);
        //        mainWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
        //        mainWindow.Show();

        //    }
        //    catch (Exception ex)
        //    {

        //        MessageBox.Show(ex.Message);
        //    }
        //}

        private void menu_SocketSetting_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Wnd_SocketSNCheckWindow.SingleShow();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }



        private void menu_Test_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Wnd_TestStation.SingleShow();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void menu_OPTRight_Click(object sender, RoutedEventArgs e)
        {
            //AviewLightSource.MainWindow mainWindow = new AviewLightSource.MainWindow(FinalTestMachine.Connect.ConnectFactory.optRight);
            //mainWindow.Title = "OPT右(平面光源)";
            //IUserLimitdll.PreControlBindingHelper.SetLitmitBinding(mainWindow, IUserLimitdll.UserLevelModes.ModifyAndOperation);
            //mainWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            //mainWindow.ShowDialog();
        }

        private void menu_DailyCheck_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Wnd_DailyCheck wnd_DailyCheck = Wnd_DailyCheck.CreateInstrance();
                wnd_DailyCheck.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        /// <summary>
        /// 寿命统计
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menu_LifeSpanstatistics_Click(object sender, RoutedEventArgs e)
        {
            Statictis.Wnd_LifeSpanStatistics window = new Statictis.Wnd_LifeSpanStatistics();
            window.Content = new AviewMotionUI.Views.MachineLife.UCMachineLifeSelectorView();
            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            window.Height = 600;
            window.Width = 900;
            window.Show();
        }

        private void menu_RunModelManager_Click(object sender, RoutedEventArgs e)
        {
            MainUnits.Wnd_RunModeSetting wnd_RunModeSetting = new Wnd_RunModeSetting();
            wnd_RunModeSetting.ShowDialog();
        }

        private void menu_Spotcheck_Click(object sender, RoutedEventArgs e)
        {
            SpotInspectionFacility.Views.SpotInspectionRegisterView productInfoView = new SpotInspectionFacility.Views.SpotInspectionRegisterView();
            Window window = new Window();
            window.Height = 500;
            window.Width = 530;
            window.Title = "SpotInspection";
            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            window.Content = productInfoView;
            window.ShowDialog();
        }



        void CreateOPTSource(string title,OPTController oPTController)
        {
            try
            {
                AviewLightSource.MainWindow mainWindow = new AviewLightSource.MainWindow(oPTController);
                mainWindow.Title = title;
                IUserLimitdll.PreControlBindingHelper.SetLitmitBinding(mainWindow, IUserLimitdll.UserLevelModes.ModifyAndOperation);
                mainWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                mainWindow.ShowDialog();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void LanMenuItem_Click(object sender, RoutedEventArgs e)
        {

        }

        private void menu_LightMotion_Click(object sender, RoutedEventArgs e)
        {
            Pipes.MainWindow mainWindow = new Pipes.MainWindow(PipeController.Cur.pipeInstance);

            mainWindow.ShowDialog();
        }

        private void menu_mesTest_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Window window = new Window();
                AM.MESAdapter.UserControl1 userControl1 = new AM.MESAdapter.UserControl1();
                window.Title = "Mes_Test";
                window.Height = 700;
                window.Width = 900;
                window.Content = userControl1;
                window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                window.Focus();
                window.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
